package com.jfcloud.mall.product.mapper;

import java.util.List;

import com.jfcloud.mall.product.domain.dto.ProductVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jfcloud.mall.product.domain.dto.ProductListVo;
import com.jfcloud.mall.product.domain.dto.ProductQueryForm;
import com.jfcloud.mall.product.domain.dto.ProductSkuVo;

public interface ProductMapper{

	@Select("<script>"
			+ "select tp.*,tpt.name as typeName "
			+ " from jfcloud_product tp left join jfcloud_product_type_ref ref on tp.id=ref.product_id"
			+ " left join jfcloud_product_type tpt on ref.type_id = tpt.id"
			+ " where 1=1 and tp.is_delete=0 "
			+ " <if test=\"typeId != null\">and tpt.id = #{typeId} </if>"
			+ "</script>")
	List<ProductListVo> getProduct(ProductQueryForm query);
	
	@Select("<script>"
			+ " select tp.*,tpt.name as typeName "
			+ " from jfcloud_product tp left join jfcloud_product_type_ref ref on tp.id=ref.product_id"
			+ " left join jfcloud_product_type tpt on ref.type_id = tpt.id"
			+ " where 1=1"
			+ " and tp.is_delete=0"
			+ " <if test=\"q.typeId != null\">and tpt.id = #{q.typeId} </if>"
			+ " order by tp.create_time desc"
			+ "</script>")
	IPage<ProductListVo> getProductPage(IPage<ProductListVo> page, @Param("q") ProductQueryForm query);
	
	@Select("<script>"
			+ "select tp.*,tpt.name as typeName "
			+ " from jfcloud_product tp left join jfcloud_product_type_ref ref on tp.id=ref.product_id"
			+ " left join jfcloud_product_type tpt on ref.type_id = tpt.id"
			+ " where 1=1"
			+ " and tp.is_delete=0"
			+ " <if test=\"q.typeId != null\">and tpt.id = #{q.typeId} </if>"
			+ "</script>")
	IPage<ProductListVo> getProductPage2(@Param("q") ProductQueryForm query, IPage<ProductListVo> page);
	
	@Select("<script>"
			+ "select tp.*,tpt.name as typeName "
			+ " from jfcloud_product tp left join jfcloud_product_type_ref ref on tp.id=ref.product_id"
			+ " left join jfcloud_product_type tpt on ref.type_id = tpt.id"
			+ " and tp.is_delete=0"
			+ " where  tp.id = #{productId} "
			+ "</script>")
	ProductSkuVo getProductDetail(Long productId);

	@Select("<script>"
			+ " select tp.*,tpt.name as typeName "
			+ " from jfcloud_product tp left join jfcloud_product_type_ref ref on tp.id=ref.product_id"
			+ " left join jfcloud_product_type tpt on ref.type_id = tpt.id"
			+ " where 1=1"
			+ " and tp.is_delete=0"
			+ " <if test=\"q.typeId != null\">and tpt.id = #{q.typeId} </if>"
			+ " <if test=\"q.typeIds != null and q.typeIds.length>0\">and tpt.id in <foreach collection=\"q.typeIds\" item=\"t\" index=\"index\" open=\"(\" close=\")\" separator=\",\">#{t}</foreach> </if>"
			+ " order by tp.create_time desc"
			+ "</script>")
	IPage<ProductVo> getProductPageList(IPage<ProductVo> page, @Param("q") ProductQueryForm query);
	
	
}
